Compare verbal and visual

We regressed compliance on social conformity, approval of the rules, and trust in science. There was a significant effect of conformity (\(b=0.4\), \(t=34\), \(p<.01\)) and of approval (\(b=0.27\), \(t=22\), \(p<.01\)) but not of trust in science (\(b=0\), \(t= 0.8\), \(p=.48\)).

Compare verbal and visual

It’s not just verbal vs. visual: how much visual?

It’s not just verbal vs. visual: how much visual?

Grammar of graphics

  • Be able to built up a plot in layers

  • Flexible in how you map data to graphical elements

  • Can be tricky at the beginning, but gets easier

  • Remember: rely on googling error messages + trying stuff

Grammar of graphics: Aesthetics

  • Data \(\longrightarrow\) columns
  • Plot \(\longrightarrow\) elements:
    • x, y axes
    • color, fill
    • size, shape, linetype, …
  • Can add summaries/styling

Grammar of graphics: Geoms

  • How to picture each aesthetic
    • Bar
    • Point
    • Density curve/violin/etc.

Example: 1 aesthetic, 3 geoms

data <- data.frame(score=rnorm(80, 5, 4))
myplot <- ggplot(data, aes(x=score))

Example: 1 aesthetic, 3 geoms

myplot + geom_density()

Example: 1 aesthetic, 3 geoms

myplot + geom_histogram()

Example: 1 aesthetic, 3 geoms

myplot + geom_dotplot()

Points: aesthetics vs style

ggplot(data_scatter,
       aes(x=x,
           y=outcome)) + 
  geom_point()

Points: aesthetics vs style

ggplot(data_scatter,
       aes(x=x,
           y=outcome)) + 
  geom_point(alpha=0.4,
             color="royalblue")

Points: aesthetics vs style

Line plots

Stats

stat_summary(fun=…) - using the same data, generate some summaries

stat_smooth(method=…) - generate a spline

## Stat_summary

Stat_summary

If you’re ever having trouble with stat_summary geom=“line” (lines look crazy, lots of up/down lines): add aes(group=…)

Stat_smooth

Stat_smooth

Labels

It’s very tempting to just use the default column names

But it is definitely worth adding more explicit labels:

  • labs(x=…, y=…, color=…, title=…)

Marginal plots

Marginal plots

Marginal plots

Nice packages